package com.meelive.ingkee.push.platform.meizu;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.meelive.ingkee.push.InkePushConfig;
import com.meelive.ingkee.push.InkePushHelper;
import com.meelive.ingkee.push.common.PushUtils;
import com.meelive.ingkee.push.model.Constance;
import com.meelive.ingkee.push.model.InkePushType;
import com.meelive.ingkee.push.platform.IPush;
import com.meizu.cloud.pushsdk.PushManager;
import com.meizu.cloud.pushsdk.util.MzSystemUtils;

import static com.meelive.ingkee.push.model.Constance.TAG;


/**
 * Create by: fanfeiyue
 * on: 2019-08-22
 * desc:
 */
public class InkeMzPush extends IPush {
    @Override
    public InkePushType getPushType() {
        return InkePushType.MEIZUPUSH;
    }

    @Override
    public void onRegister(Context context, InkePushConfig config) {
        if (PushUtils.DEBUG) {
            Log.d(TAG, "InkeMZPush onRegister");
        }
        boolean support = MzSystemUtils.isBrandMeizu(context);
        if (!support) {
            InkePushHelper.getInstance().onErrorResponse(getPushType(), Constance.PUSH_NOT_SUPPORT, Constance.PUSH_NOT_SUPPORT_MSG);
            return;
        }
        String pushId = PushManager.getPushId(context);
        if (TextUtils.isEmpty(pushId)) {
            PushManager.register(context, config.getMzAppId(), config.getMzAppKey());
        } else {
            InkePushHelper.getInstance().onReceiveToken(getPushType(), pushId);
        }
    }

    @Override
    public void onUnregister(Context context, InkePushConfig config) {
        PushManager.unRegister(context);
    }

}
